﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.cms.businesslogic.datatype;

namespace ScDataTypes.DataTypes
{

    public class MediaTreeviewDropDownListDataType : umbraco.cms.businesslogic.datatype.AbstractDataEditor
    {

        #region Variables

        MediaTreeviewDropDownList _MediaTreeviewDropDownList = new MediaTreeviewDropDownList();

        #endregion

        #region Properties

        [DataEditorSetting("MediaType", description = "Allowed document type", defaultValue = "")]
        public string DocumentType
        {
            get { return this._MediaTreeviewDropDownList.MediaType; }
            set { this._MediaTreeviewDropDownList.MediaType = value; }
        }

        [DataEditorSetting("Location", description = "Inital location", defaultValue = "")]
        public string Location
        {
            get { return this._MediaTreeviewDropDownList.Location; }
            set { this._MediaTreeviewDropDownList.Location = value; }
        }

        /// <summary>
        /// Unique id for the datatype
        /// </summary>
        public override Guid Id { get { return new Guid("E3150ACC-9DBA-4494-85A6-D24A4ED66D30"); } }

        /// <summary>
        /// Name of the datatype
        /// </summary>
        public override string DataTypeName { get { return "Media TreeView DropDownList"; } }

        #endregion

        #region Constructor

        public MediaTreeviewDropDownListDataType()
            : base()
        {
            //set rendercontrol
            base.RenderControl = this._MediaTreeviewDropDownList;

            //init event            
            this._MediaTreeviewDropDownList.Init += new EventHandler(MediaTreeviewDropDownList_Initalised);

            //save event
            base.DataEditorControl.OnSave += new AbstractDataEditorControl.SaveEventHandler(ContentTreeview_Saving);
        }

        #endregion

        #region Control Initalisation

        void MediaTreeviewDropDownList_Initalised(object sender, EventArgs e)
        {
            if (base.Data.Value != null)
                this._MediaTreeviewDropDownList.Selected = base.Data.Value.ToString();
        }

        #endregion

        #region Saving

        void ContentTreeview_Saving(EventArgs e)
        {
            base.Data.Value = this._MediaTreeviewDropDownList.Selected;
        }

        #endregion

    }

}